package a8;

import java.util.Random;
import java.util.Scanner;

public class Player extends Game{

	public Player() {

	}
	/**
	 * Computer player method.
	 * @param pile
	 * @param a AI option.
	 */
	public void play(Pile pile, int a) {
		if(a == 0) // Dumb
		{
			Random random = new Random();
			int rand = random.nextInt(pile.getTotal()/2) + 1;
			pile.take(rand);
			System.out.println("Computer takes " + rand);
		}
		else // Smart
		{
			Random random = new Random();
			int x = pile.getTotal();
			if( x > 63)
				x -=  63;
			else if( x > 31)
				x -= 31;
			else if (x > 15)
				x -= 15;
			else if (x > 7)
				x -= 7;
			else if(x > 3)
				x -= 3;
			else
				x = random.nextInt(3) + 1;
			pile.take(x);
			System.out.println("Computer takes " + x);
			
		}

	}
	/**
	 * Human player menu
	 * @param pile
	 */
	public void play(Pile pile) {
		System.out.println("The current marbles are "+ pile.getTotal()+ " How many do you want to take?");
		Scanner input = new Scanner(System.in);
		int x = input.nextInt();
		if(x > pile.getTotal())
		{
			System.out.println("Insert an input in range");
			x = input.nextInt();
		}
		
		pile.take(x);
		System.out.println("Amount taken " + x);
		
	}
}
